﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability.Commont.Domains.BatchManagementFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.EndingOnly
{
    public class BulkSlaughterSearchHandler : IRequestHandler<BulkSlaughterSearchCommand, Resqults>
    {
        private readonly IBateRepository<BulkSlaughter> _bulkslaughterRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="bulkslaughterRepository"></param>
        public BulkSlaughterSearchHandler(IBateRepository<BulkSlaughter> bulkslaughterRepository)
        {
            _bulkslaughterRepository = bulkslaughterRepository;
        }
        /// <summary>
        /// 批宰计划列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Resqults> Handle(BulkSlaughterSearchCommand request, CancellationToken cancellationToken)
        {
            var resqults = new Resqults() { Code = 0 };
            try
            {
                var list = await _bulkslaughterRepository.GetAll().Where(p => p.Stact == 0).ToListAsync();
                if (list != null)
                {
                    resqults.Code = 1;
                    resqults.Date = list;
                    resqults.Messges = "批宰计划显示成功";
                }
            }
            catch (Exception)
            {

                resqults.Messges = "批宰计划显示失败";
            }
            return resqults;
        }
    }
}
